import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CustomNotification extends Notification {
  final String msg;

  CustomNotification({this.msg});
}


class CustomChild extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RaisedButton(onPressed: ()=> CustomNotification(msg:"Hi").dispatch(context),child:Text("Fire"));
  }
}

class NotificationPageView extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {

    return NotificationState();
  }
}

class NotificationState extends State<NotificationPageView> {

  String msg = "";

  @override
  Widget build(BuildContext context) {
    return NotificationListener<CustomNotification>(
      onNotification: (notification) {
        setState(() {
          msg += notification.msg;
        });
      },
      child: Column(
        children: [
          Text(msg),
          CustomChild()
        ],
      ),
    );
  }
}

